<?php
namespace Dybasedev\Dataman\Convert;

use Illuminate\Database\ConnectionInterface;
use Closure;

class Builder
{
    protected $connection;

    public function __construct(ConnectionInterface $connection)
    {
        $this->connection = $connection;
    }

    public function test() {
        printf("hi");
    }

    public function simple($from, $to, Closure $callback, Closure $event)
    {
        $converter = $this->getConverter($from, $to);

        $callback($converter);

        $converter->build($event);
    }

    public function getConverter($from, $to)
    {
        $converter = new Converter($this->connection, $from, $to);

        $converter->setOriginTable($this->wrapTable($from));

        $converter->setTargetTable($this->wrapTable($to));

        return $converter;
    }

    public function wrapTable($table)
    {
        if (is_array($table)) {
            return $table[0] . '.' . $table[1];
        }

        return $table;
    }
}